package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

// Bottle holds the schema definition for the Bottle entity.
type Bottle struct {
	ent.Schema
}

// Fields of the Bottle.
func (Bottle) Fields() []ent.Field {
	return []ent.Field{
		field.Text("content").
			NotEmpty().
			Comment("内容"),
		field.JSON("images", []string{}).
			Optional().
			Comment("图片URL数组"),
		field.Int64("creator_id").
			Comment("创建者ID"),
		field.Time("deleted_at").
			Optional().
			Nillable().
			Comment("软删除时间"),
		field.Time("created_at").
			Default(time.Now).
			Immutable().
			Comment("创建时间"),
		field.Time("updated_at").
			Default(time.Now).
			UpdateDefault(time.Now).
			Comment("更新时间"),
	}
}

// Edges of the Bottle.
func (Bottle) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("creator", User.Type).
			Ref("bottles").
			Field("creator_id").
			Unique().
			Required(),
	}
}
